package giit.computerbase.server;

import giit.computerbase.dao.MySQL;
import giit.computerbase.dao.SQL;
import giit.computerbase.util.Application;

import java.io.File;

/**
 * User: tum0r
 * Package Name: giit.computerbase.server
 * Time: 2018-11-29 Thursday 19:03:42
 */
public class DeleteServer {
    private SQL sql;

    public DeleteServer() {
        try {
            sql = new MySQL();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        sql.open((String) Application.getConfig().databaseConfig.get("address"),
                (int) Application.getConfig().databaseConfig.get("port"),
                Application.DATABASE_NAME,
                (String) Application.getConfig().databaseConfig.get("encode"),
                (String) Application.getConfig().databaseConfig.get("user"),
                (String) Application.getConfig().databaseConfig.get("password"));
    }

    public boolean delete(String title) {
        boolean flag = sql.delete("delete from activity_information where title=?", new Object[]{title});
        if (flag) {
            File file = new File(Application.PATH + File.separator + "upload" + File.separator + title + File.separator);
            if (file.exists()) {
                File[] files = file.listFiles();
                for (File temp : files) {
                    temp.delete();
                }
            }
        }
        return flag;
    }
}
